using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace AppManagement.Repositories
{
	#region using
	using AppManagement.Models;
	#endregion
	public class ChiSo_DichVuRepository
	{
		public static List<ChiSo_DichVu> SelectAll()
		{
			return DataContext.Instance.ChiSo_DichVu.ToList();
		}

		public static ChiSo_DichVu SelectByID(int macsdv)
		{
			return DataContext.Instance.ChiSo_DichVu.FirstOrDefault(item => item.MaCSDV == macsdv );
		}

		public static bool Insert(ChiSo_DichVu obj)
		{
			try
			{
				DataContext.Instance.ChiSo_DichVu.AddObject(obj);
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static bool Delete(int macsdv)
		{
			try
			{
				var delitem = DataContext.Instance.ChiSo_DichVu.FirstOrDefault(item => item.MaCSDV == macsdv );
				DataContext.Instance.ChiSo_DichVu.DeleteObject(delitem);
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static bool Save()
		{
			try
			{
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static List<ChiSo_DichVu> RetrieveByID(int macsdv)
		{
			return (from item in DataContext.Instance.ChiSo_DichVu where  item.MaCSDV == macsdv  select item).ToList();
		}

		public static List<ChiSo_DichVu> SelectByMaDV(string madv)
		{
			var lstItem = (from item in DataContext.Instance.ChiSo_DichVu where item.MaDV == madv select item).ToList();
			return lstItem;
		}

		public static List<ChiSo_DichVu> SelectByMaCS(string macs)
		{
			var lstItem = (from item in DataContext.Instance.ChiSo_DichVu where item.MaCS == macs select item).ToList();
			return lstItem;
		}

	}
}